package com.example.pilipili.controller;


import com.example.pilipili.common.R;
import com.example.pilipili.pojo.entity.Follow;
import com.example.pilipili.pojo.entity.Like;
import com.example.pilipili.service.FollowService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liyv
 * @since 2023-12-01
 */
@RestController
@RequestMapping("/follow")
public class FollowController {

    @Autowired
    FollowService followService ;

    /**
     * 点击关注按钮
     * @param follow uid,vid
     * @return
     */
    @PostMapping
    public R<Follow> addLike(@RequestBody @Valid Follow follow){
        return followService.click(follow) ;
    }

    /**
     * 某用户对视频发布者 是否关注
     * @param follow ing ， ed
     * @return boolean
     */
    @PostMapping("/init")
    public R getInitForU(@RequestBody @Valid Follow follow){
        return R.ok(followService.isFollow(follow.getfIng(),follow.getfEd())) ;
    }

    /**
     * 获取用户 粉丝数，关注数
     * @param uid uid
     * @return [fans,follow]
     */
    @GetMapping("/nums/{uid}")
    public R getNums(@PathVariable int uid){
        Map<String,Integer> data = new HashMap<>() ;
        data.put("fans",followService.UFEdNums(uid));
        data.put("follow",followService.UFIngNums(uid));
        return R.ok(data) ;
    }

}

